package com.zlei.code.review;

import com.zlei.code.binaryTree.TreeNode;

import java.util.Stack;

/**
 * @Author leizhang76
 * @Date 2021/2/23 10:08
 */
public class Review2 {

    /**
     * 二叉树的非递归前序遍历
     * @param root
     */
    public void pre(TreeNode root){
        if (root==null){
            return;
        }
        Stack<TreeNode> stack=new Stack<>();
        TreeNode temp=root;
        stack.push(temp);
        while (!stack.isEmpty()){
            TreeNode pop = stack.pop();
            System.out.println(pop.val);
            if (pop.right!=null){
                stack.push(pop.right);
            }
            if (pop.left!=null){
                stack.push(pop.left);
            }
        }
    }

    /**
     * 二叉树的中序非递归遍历
     * @param root
     */
    public void inOrder(TreeNode root){
        Stack<TreeNode> stack=new Stack<>();
        TreeNode temp=root;
        while (!stack.isEmpty()||temp!=null){
            while (temp!=null){
                stack.push(temp);
                temp=temp.left;
            }
            temp= stack.pop();
            System.out.println(temp.val);
            if (temp.right!=null){
                stack.push(temp.right);
            }else {
                temp=null;
            }
        }
    }

    /**
     * 二叉树的非递归后续遍历
     * @param root
     */
    public void post(TreeNode root){

    }


}
